/*
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
package l2s.gameserver.scripts.quests;

import l2s.gameserver.model.actor.L2Npc;
import l2s.gameserver.model.actor.instance.L2PcInstance;
import l2s.gameserver.model.quest.Quest;
import l2s.gameserver.model.quest.QuestState;
import l2s.gameserver.scripting.ScriptFile;

public class Q221_TestimonyOfProsperity extends Quest implements ScriptFile
{
	private static final String qn = "Q221_TestimonyOfProsperity";
	private static final int Parman = 30104;
	private static final int Bright = 30466;
	private static final int Emily = 30620;
	private static final int Piotur = 30597;
	private static final int Wilford = 30005;
	private static final int Lilith = 30368;
	private static final int Lockirin = 30531;
	private static final int Spiron = 30532;
	private static final int Shari = 30517;
	private static final int Balanki = 30533;
	private static final int Mion = 30519;
	private static final int Redbonnet = 30553;
	private static final int Keef = 30534;
	private static final int Torocco = 30555;
	private static final int Filaur = 30535;
	private static final int Bolter = 30554;
	private static final int Arin = 30536;
	private static final int Toma = 30556;
	private static final int Nikola = 30621;
	private static final int BoxOfTitan = 30622;
	private static final int RingOfTestimony1st = 3239;
	private static final int BrightsList = 3264;
	private static final int MandragoraPetal = 3265;
	private static final int CrimsonMoss = 3266;
	private static final int MandragoraBouquet = 3267;
	private static final int EmilysRecipe = 3243;
	private static final int BlessedSeed = 3242;
	private static final int CrystalBrooch = 3428;
	private static final int LilithsElvenWafer = 3244;
	private static final int CollectionLicense = 3246;
	private static final int Lockirins1stNotice = 3247;
	private static final int ContributionOfShari = 3252;
	private static final int ReceiptOfContribution1st = 3258;
	private static final int Lockirins2stNotice = 3248;
	private static final int ContributionOfMion = 3253;
	private static final int MarysesRequest = 3255;
	private static final int ContributionOfMaryse = 3254;
	private static final int ReceiptOfContribution2st = 3259;
	private static final int Lockirins3stNotice = 3249;
	private static final int ProcurationOfTorocco = 3263;
	private static final int ReceiptOfContribution3st = 3260;
	private static final int Lockirins4stNotice = 3250;
	private static final int ReceiptOfBolter = 3257;
	private static final int ReceiptOfContribution4st = 3261;
	private static final int Lockirins5stNotice = 3251;
	private static final int ContributionOfToma = 3256;
	private static final int ReceiptOfContribution5st = 3262;
	private static final int OldAccountBook = 3241;
	private static final int ParmansInstructions = 3268;
	private static final int ParmansLetter = 3269;
	private static final int RingOfTestimony2st = 3240;
	private static final int ClayDough = 3270;
	private static final int PatternOfKeyhole = 3271;
	private static final int NikolasList = 3272;
	private static final int RecipeTitanKey = 3023;
	private static final int MaphrTabletFragment = 3245;
	private static final int StakatoShell = 3273;
	private static final int ToadLordSac = 3274;
	private static final int SpiderThorn = 3275;
	private static final int KeyOfTitan = 3030;
	private static final int MarkOfProsperity = 3238;
	private static final int AnimalSkin = 1867;
	private static final int Adena = 57;
	private static final int MandragoraSprout = 20154;
	private static final int MandragoraSapling = 20155;
	private static final int MandragoraBlossom = 20156;
	private static final int MandragoraSprout2 = 20223;
	private static final int GiantCrimsonAnt = 20228;
	private static final int MarshStakato = 20157;
	private static final int MarshStakatoWorker = 20230;
	private static final int MarshStakatoSoldier = 20232;
	private static final int MarshStakatoDrone = 20234;
	private static final int ToadLord = 20231;
	private static final int MarshSpider = 20233;
	private static final int[][] DROPLIST_COND =
	{
		{
			1,
			0,
			MandragoraSprout,
			BrightsList,
			MandragoraPetal,
			20,
			60,
			1
		},
		{
			1,
			0,
			MandragoraSapling,
			BrightsList,
			MandragoraPetal,
			20,
			80,
			1
		},
		{
			1,
			0,
			MandragoraBlossom,
			BrightsList,
			MandragoraPetal,
			20,
			100,
			1
		},
		{
			1,
			0,
			MandragoraSprout2,
			BrightsList,
			MandragoraPetal,
			20,
			30,
			1
		},
		{
			1,
			0,
			GiantCrimsonAnt,
			BrightsList,
			CrimsonMoss,
			10,
			100,
			1
		},
		{
			7,
			0,
			MarshStakato,
			0,
			StakatoShell,
			20,
			20,
			1
		},
		{
			7,
			0,
			MarshStakatoWorker,
			0,
			StakatoShell,
			20,
			30,
			1
		},
		{
			7,
			0,
			MarshStakatoSoldier,
			0,
			StakatoShell,
			20,
			50,
			1
		},
		{
			7,
			0,
			MarshStakatoDrone,
			0,
			StakatoShell,
			20,
			60,
			1
		},
		{
			7,
			0,
			ToadLord,
			0,
			ToadLordSac,
			10,
			50,
			1
		},
		{
			7,
			0,
			MarshSpider,
			0,
			SpiderThorn,
			10,
			50,
			1
		}
	};
	private static boolean QuestProf = true;
	
	public Q221_TestimonyOfProsperity(int questId, String name, String descr)
	{
		super(questId, name, descr);
		addStartNpc(Parman);
		addTalkId(Bright);
		addTalkId(Emily);
		addTalkId(Piotur);
		addTalkId(Wilford);
		addTalkId(Lilith);
		addTalkId(Shari);
		addTalkId(Mion);
		addTalkId(Lockirin);
		addTalkId(Spiron);
		addTalkId(Balanki);
		addTalkId(Keef);
		addTalkId(Filaur);
		addTalkId(Arin);
		addTalkId(Redbonnet);
		addTalkId(Bolter);
		addTalkId(Torocco);
		addTalkId(Toma);
		addTalkId(Nikola);
		addTalkId(BoxOfTitan);
		for (int[] element : DROPLIST_COND)
		{
			addKillId(element[2]);
		}
		questItemIds = new int[]
		{
			RingOfTestimony1st,
			BrightsList,
			MandragoraBouquet,
			BlessedSeed,
			EmilysRecipe,
			CrystalBrooch,
			LilithsElvenWafer,
			CollectionLicense,
			Lockirins1stNotice,
			Lockirins2stNotice,
			Lockirins3stNotice,
			Lockirins4stNotice,
			Lockirins5stNotice,
			ReceiptOfContribution1st,
			ReceiptOfContribution2st,
			ReceiptOfContribution3st,
			ReceiptOfContribution4st,
			ReceiptOfContribution5st,
			OldAccountBook,
			ContributionOfShari,
			ContributionOfMaryse,
			ContributionOfMion,
			ProcurationOfTorocco,
			ReceiptOfBolter,
			ContributionOfToma,
			MarysesRequest,
			ParmansInstructions,
			RingOfTestimony2st,
			MaphrTabletFragment,
			PatternOfKeyhole,
			ClayDough,
			NikolasList,
			MandragoraPetal,
			CrimsonMoss,
			StakatoShell,
			ToadLordSac,
			SpiderThorn
		};
	}
	
	@Override
	public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
	
	{
		String htmltext = event;
		QuestState st = player.getQuestState(qn);
		if (event.equalsIgnoreCase("30104-04.htm"))
		{
			st.giveItems(7562, 64);
			st.playSound(QuestState.SOUND_ACCEPT);
			st.giveItems(RingOfTestimony1st, 1);
			st.set("cond", "1");
			st.setState(Quest.STATE_STARTED);
		}
		else if (event.equalsIgnoreCase("30466-03.htm"))
		{
			st.giveItems(BrightsList, 1);
		}
		else if (event.equalsIgnoreCase("30620-03.htm"))
		{
			st.takeItems(MandragoraBouquet, -1);
			st.giveItems(EmilysRecipe, 1);
			htmltext = "30620-03.htm";
			if ((st.getQuestItemsCount(OldAccountBook) > 0) && (st.getQuestItemsCount(BlessedSeed) > 0) && (st.getQuestItemsCount(EmilysRecipe) > 0) && (st.getQuestItemsCount(LilithsElvenWafer) > 0))
			{
				st.set("cond", "2");
				st.setState(Quest.STATE_STARTED);
			}
		}
		else if (event.equalsIgnoreCase("30597-02.htm"))
		{
			st.giveItems(BlessedSeed, 1);
			if ((st.getQuestItemsCount(OldAccountBook) > 0) && (st.getQuestItemsCount(BlessedSeed) > 0) && (st.getQuestItemsCount(EmilysRecipe) > 0) && (st.getQuestItemsCount(LilithsElvenWafer) > 0))
			{
				st.set("cond", "2");
				st.setState(Quest.STATE_STARTED);
			}
		}
		else if (event.equalsIgnoreCase("30005-04.htm"))
		{
			st.giveItems(CrystalBrooch, 1);
		}
		else if (event.equalsIgnoreCase("30368-03.htm"))
		{
			st.takeItems(CrystalBrooch, -1);
			st.giveItems(LilithsElvenWafer, 1);
			if ((st.getQuestItemsCount(OldAccountBook) > 0) && (st.getQuestItemsCount(BlessedSeed) > 0) && (st.getQuestItemsCount(EmilysRecipe) > 0) && (st.getQuestItemsCount(LilithsElvenWafer) > 0))
			{
				st.set("cond", "2");
				st.setState(Quest.STATE_STARTED);
			}
		}
		else if (event.equalsIgnoreCase("30531-03.htm"))
		{
			st.giveItems(CollectionLicense, 1);
			st.giveItems(Lockirins1stNotice, 1);
			st.giveItems(Lockirins2stNotice, 1);
			st.giveItems(Lockirins3stNotice, 1);
			st.giveItems(Lockirins4stNotice, 1);
			st.giveItems(Lockirins5stNotice, 1);
		}
		else if (event.equalsIgnoreCase("30555-02.htm"))
		{
			st.giveItems(ProcurationOfTorocco, 1);
		}
		else if (event.equalsIgnoreCase("30534-03a.htm") && (st.getQuestItemsCount(Adena) >= 5000))
		{
			htmltext = "30534-03b.htm";
			st.takeItems(Adena, 5000);
			st.takeItems(ProcurationOfTorocco, -1);
			st.giveItems(ReceiptOfContribution3st, 1);
		}
		else if (event.equalsIgnoreCase("30104-07.htm"))
		{
			st.takeItems(RingOfTestimony1st, -1);
			st.takeItems(OldAccountBook, -1);
			st.takeItems(BlessedSeed, -1);
			st.takeItems(EmilysRecipe, -1);
			st.takeItems(LilithsElvenWafer, -1);
			if (st.getPlayer().getLevel() < 38)
			{
				st.giveItems(ParmansInstructions, 1);
				st.set("cond", "3");
				st.setState(Quest.STATE_STARTED);
			}
			else
			{
				st.giveItems(ParmansLetter, 1);
				st.giveItems(RingOfTestimony2st, 1);
				htmltext = "30104-08.htm";
				st.set("cond", "4");
				st.setState(Quest.STATE_STARTED);
			}
		}
		else if (event.equalsIgnoreCase("30621-04.htm"))
		{
			st.giveItems(ClayDough, 1);
			st.set("cond", "5");
			st.setState(Quest.STATE_STARTED);
		}
		else if (event.equalsIgnoreCase("30622-02.htm"))
		{
			st.takeItems(ClayDough, -1);
			st.giveItems(PatternOfKeyhole, 1);
			st.set("cond", "6");
			st.setState(Quest.STATE_STARTED);
		}
		else if (event.equalsIgnoreCase("30622-04.htm"))
		{
			st.takeItems(NikolasList, -1);
			st.takeItems(KeyOfTitan, 1);
			st.giveItems(MaphrTabletFragment, 1);
			st.set("cond", "9");
			st.setState(Quest.STATE_STARTED);
		}
		return htmltext;
	}
	
	@Override
	public String onTalk(L2Npc npc, L2PcInstance player)
	{
		int npcId = npc.getNpcId();
		QuestState st = checkPlayerState(player, npc, STATE_STARTED);
		if (st == null)
		{
			return null;
		}
		String htmltext = getNoQuestMsg();
		int cond = st.getInt("cond");
		if (npcId == Parman)
		{
			if (st.getQuestItemsCount(MarkOfProsperity) != 0)
			{
				htmltext = getAlreadyCompletedMsg();
				st.exitQuest(true);
			}
			else if (cond == 0)
			{
				if (st.getPlayer().getRace().ordinal() == 4)
				{
					if (st.getPlayer().getLevel() >= 37)
					{
						htmltext = "30104-03.htm";
					}
					else
					{
						htmltext = "30104-02.htm";
						st.exitQuest(true);
					}
				}
				else
				{
					htmltext = "30104-01.htm";
					st.exitQuest(true);
				}
			}
			else if (cond == 1)
			{
				htmltext = "30104-05.htm";
			}
			else if (cond == 2)
			{
				if ((st.getQuestItemsCount(OldAccountBook) > 0) && (st.getQuestItemsCount(BlessedSeed) > 0) && (st.getQuestItemsCount(EmilysRecipe) > 0) && (st.getQuestItemsCount(LilithsElvenWafer) > 0))
				{
					htmltext = "30104-06.htm";
				}
			}
			else if ((cond == 3) && (st.getQuestItemsCount(ParmansInstructions) > 0))
			{
				if (st.getPlayer().getLevel() < 38)
				{
					htmltext = "30104-09.htm";
				}
				else
				{
					htmltext = "30104-10.htm";
					st.takeItems(ParmansInstructions, -1);
					st.giveItems(RingOfTestimony2st, 1);
					st.giveItems(ParmansLetter, 1);
					st.set("cond", "4");
					st.setState(Quest.STATE_STARTED);
				}
			}
			else if ((cond == 4) && (st.getQuestItemsCount(RingOfTestimony2st) > 0) && (st.getQuestItemsCount(ParmansLetter) > 0) && (st.getQuestItemsCount(MaphrTabletFragment) == 0))
			{
				htmltext = "30104-11.htm";
			}
			else if ((cond >= 5) && (cond <= 7))
			{
				htmltext = "30104-12.htm";
			}
			else if (cond == 9)
			{
				st.getPlayer().addExpAndSp(25000, 3100);
				st.takeItems(RingOfTestimony2st, -1);
				st.takeItems(MaphrTabletFragment, -1);
				st.giveItems(MarkOfProsperity, 1);
				htmltext = "30104-13.htm";
				st.playSound(QuestState.SOUND_FINISH);
				st.exitQuest(true);
			}
		}
		else if (npcId == Lockirin)
		{
			if (st.getQuestItemsCount(CollectionLicense) == 0)
			{
				htmltext = "30531-01.htm";
			}
			else if (st.getQuestItemsCount(CollectionLicense) > 0)
			{
				if ((st.getQuestItemsCount(ReceiptOfContribution1st) > 0) && (st.getQuestItemsCount(ReceiptOfContribution2st) > 0) && (st.getQuestItemsCount(ReceiptOfContribution3st) > 0) && (st.getQuestItemsCount(ReceiptOfContribution4st) > 0) && (st.getQuestItemsCount(ReceiptOfContribution5st) > 0))
				{
					htmltext = "30531-05.htm";
					st.takeItems(CollectionLicense, -1);
					st.takeItems(ReceiptOfContribution1st, -1);
					st.takeItems(ReceiptOfContribution2st, -1);
					st.takeItems(ReceiptOfContribution3st, -1);
					st.takeItems(ReceiptOfContribution4st, -1);
					st.takeItems(ReceiptOfContribution5st, -1);
					st.giveItems(OldAccountBook, 1);
					if ((st.getQuestItemsCount(OldAccountBook) > 0) && (st.getQuestItemsCount(BlessedSeed) > 0) && (st.getQuestItemsCount(EmilysRecipe) > 0) && (st.getQuestItemsCount(LilithsElvenWafer) > 0))
					{
						st.set("cond", "2");
					}
				}
				else
				{
					htmltext = "30531-04.htm";
				}
			}
			else if ((cond >= 1) && (st.getQuestItemsCount(RingOfTestimony1st) > 0) && (st.getQuestItemsCount(OldAccountBook) > 0) && (st.getQuestItemsCount(CollectionLicense) == 0))
			{
				htmltext = "30531-06.htm";
			}
			else if ((cond >= 1) && (st.getQuestItemsCount(RingOfTestimony2st) > 0))
			{
				htmltext = "30531-07.htm";
			}
		}
		else if ((npcId == Spiron) && (cond == 1) && (st.getQuestItemsCount(CollectionLicense) > 0))
		{
			if (st.getQuestItemsCount(Lockirins1stNotice) > 0)
			{
				htmltext = "30532-01.htm";
				st.takeItems(Lockirins1stNotice, -1);
			}
			else if ((st.getQuestItemsCount(ReceiptOfContribution1st) == 0) && (st.getQuestItemsCount(ContributionOfShari) == 0))
			{
				htmltext = "30532-02.htm";
			}
			else if (st.getQuestItemsCount(ContributionOfShari) > 0)
			{
				st.takeItems(ContributionOfShari, -1);
				st.giveItems(ReceiptOfContribution1st, 1);
				htmltext = "30532-03.htm";
			}
			else if (st.getQuestItemsCount(ReceiptOfContribution1st) > 0)
			{
				htmltext = "30532-04.htm";
			}
		}
		else if ((npcId == Shari) && (cond == 1) && (st.getQuestItemsCount(CollectionLicense) > 0) && (st.getQuestItemsCount(Lockirins1stNotice) == 0) && (st.getQuestItemsCount(ReceiptOfContribution1st) == 0))
		{
			if (st.getQuestItemsCount(ContributionOfShari) == 0)
			{
				st.giveItems(ContributionOfShari, 1);
				htmltext = "30517-01.htm";
			}
			else
			{
				htmltext = "30517-02.htm";
			}
		}
		else if ((npcId == Balanki) && (cond == 1) && (st.getQuestItemsCount(CollectionLicense) > 0))
		{
			if (st.getQuestItemsCount(Lockirins2stNotice) > 0)
			{
				htmltext = "30533-01.htm";
				st.takeItems(Lockirins2stNotice, -1);
			}
			else if ((st.getQuestItemsCount(ReceiptOfContribution2st) == 0) && ((st.getQuestItemsCount(ContributionOfMion) == 0) || (st.getQuestItemsCount(ContributionOfMaryse) == 0)))
			{
				htmltext = "30533-02.htm";
			}
			else if ((st.getQuestItemsCount(ContributionOfMion) != 0) && (st.getQuestItemsCount(ContributionOfMaryse) != 0))
			{
				htmltext = "30533-03.htm";
				st.takeItems(ContributionOfMaryse, -1);
				st.takeItems(ContributionOfMion, -1);
				st.giveItems(ReceiptOfContribution2st, 1);
			}
			else if (st.getQuestItemsCount(ReceiptOfContribution2st) > 0)
			{
				htmltext = "30533-04.htm";
			}
		}
		else if ((npcId == Mion) && (cond == 1) && (st.getQuestItemsCount(CollectionLicense) > 0) && (st.getQuestItemsCount(Lockirins2stNotice) == 0) && (st.getQuestItemsCount(ReceiptOfContribution2st) == 0))
		{
			if (st.getQuestItemsCount(ContributionOfMion) == 0)
			{
				htmltext = "30519-01.htm";
				st.giveItems(ContributionOfMion, 1);
			}
			else
			{
				htmltext = "30519-02.htm";
			}
		}
		else if ((npcId == Redbonnet) && (cond == 1) && (st.getQuestItemsCount(CollectionLicense) > 0) && (st.getQuestItemsCount(Lockirins2stNotice) == 0) && (st.getQuestItemsCount(ReceiptOfContribution2st) == 0))
		{
			if ((st.getQuestItemsCount(MarysesRequest) == 0) && (st.getQuestItemsCount(ContributionOfMaryse) == 0))
			{
				htmltext = "30553-01.htm";
				st.giveItems(MarysesRequest, 1);
			}
			else if ((st.getQuestItemsCount(MarysesRequest) > 0) && (st.getQuestItemsCount(ContributionOfMaryse) == 0))
			{
				if (st.getQuestItemsCount(AnimalSkin) < 100)
				{
					htmltext = "30553-02.htm";
				}
				else
				{
					htmltext = "30553-03.htm";
					st.takeItems(AnimalSkin, 100);
					st.takeItems(MarysesRequest, -1);
					st.giveItems(ContributionOfMaryse, 1);
				}
			}
			else if (st.getQuestItemsCount(ContributionOfMaryse) > 0)
			{
				htmltext = "30553-04.htm";
			}
		}
		else if ((npcId == Keef) && (cond == 1) && (st.getQuestItemsCount(CollectionLicense) > 0))
		{
			if (st.getQuestItemsCount(Lockirins3stNotice) > 0)
			{
				htmltext = "30534-01.htm";
				st.takeItems(Lockirins3stNotice, -1);
			}
			else if ((st.getQuestItemsCount(ReceiptOfContribution3st) == 0) && (st.getQuestItemsCount(ProcurationOfTorocco) == 0))
			{
				htmltext = "30534-02.htm";
			}
			else if ((st.getQuestItemsCount(ReceiptOfContribution3st) == 0) && (st.getQuestItemsCount(ProcurationOfTorocco) > 0))
			{
				htmltext = "30534-03.htm";
			}
			else if (st.getQuestItemsCount(ReceiptOfContribution3st) > 0)
			{
				htmltext = "30534-04.htm";
			}
		}
		else if ((npcId == Torocco) && (cond == 1) && (st.getQuestItemsCount(CollectionLicense) > 0) && (st.getQuestItemsCount(Lockirins3stNotice) == 0) && (st.getQuestItemsCount(ReceiptOfContribution3st) == 0))
		{
			if (st.getQuestItemsCount(ProcurationOfTorocco) == 0)
			{
				htmltext = "30555-01.htm";
			}
			else if (st.getQuestItemsCount(ProcurationOfTorocco) > 0)
			{
				htmltext = "30555-03.htm";
			}
		}
		else if ((npcId == Filaur) && (cond == 1) && (st.getQuestItemsCount(CollectionLicense) > 0))
		{
			if (st.getQuestItemsCount(Lockirins4stNotice) > 0)
			{
				htmltext = "30535-01.htm";
				st.takeItems(Lockirins4stNotice, -1);
			}
			else if ((st.getQuestItemsCount(ReceiptOfContribution4st) == 0) && (st.getQuestItemsCount(ReceiptOfBolter) == 0))
			{
				htmltext = "30535-02.htm";
			}
			else if ((st.getQuestItemsCount(ReceiptOfBolter) > 0) && (st.getQuestItemsCount(ReceiptOfContribution4st) == 0))
			{
				htmltext = "30535-03.htm";
				st.takeItems(ReceiptOfBolter, -1);
				st.giveItems(ReceiptOfContribution4st, 1);
			}
			else if ((st.getQuestItemsCount(CollectionLicense) > 0) && (st.getQuestItemsCount(ReceiptOfContribution4st) > 0) && (st.getQuestItemsCount(ReceiptOfBolter) == 0) && (st.getQuestItemsCount(Lockirins4stNotice) == 0))
			{
				htmltext = "30535-04.htm";
			}
		}
		else if ((npcId == Bolter) && (cond == 1) && (st.getQuestItemsCount(CollectionLicense) > 0) && (st.getQuestItemsCount(Lockirins4stNotice) == 0) && (st.getQuestItemsCount(ReceiptOfContribution4st) == 0))
		{
			if (st.getQuestItemsCount(ReceiptOfBolter) == 0)
			{
				htmltext = "30554-01.htm";
				st.giveItems(ReceiptOfBolter, 1);
			}
			else
			{
				htmltext = "30554-02.htm";
			}
		}
		else if ((npcId == Arin) && (cond == 1) && (st.getQuestItemsCount(CollectionLicense) > 0))
		{
			if (st.getQuestItemsCount(Lockirins5stNotice) > 0)
			{
				htmltext = "30536-01.htm";
				st.takeItems(Lockirins5stNotice, -1);
			}
			else if ((st.getQuestItemsCount(ReceiptOfContribution5st) == 0) && (st.getQuestItemsCount(ContributionOfToma) == 0))
			{
				htmltext = "30536-02.htm";
			}
			else if ((st.getQuestItemsCount(ReceiptOfContribution5st) == 0) && (st.getQuestItemsCount(ContributionOfToma) > 0))
			{
				htmltext = "30536-03.htm";
				st.takeItems(ContributionOfToma, -1);
				st.giveItems(ReceiptOfContribution5st, 1);
			}
			else
			{
				htmltext = "30536-04.htm";
			}
		}
		else if ((npcId == Toma) && (cond == 1) && (st.getQuestItemsCount(CollectionLicense) > 0) && (st.getQuestItemsCount(Lockirins5stNotice) == 0) && (st.getQuestItemsCount(ReceiptOfContribution5st) == 0))
		{
			if (st.getQuestItemsCount(ContributionOfToma) == 0)
			{
				htmltext = "30556-01.htm";
				st.giveItems(ContributionOfToma, 1);
			}
			else
			{
				htmltext = "30556-02.htm";
			}
		}
		else if (npcId == Piotur)
		{
			if (cond == 1)
			{
				if (st.getQuestItemsCount(BlessedSeed) == 0)
				{
					htmltext = "30597-01.htm";
				}
				else
				{
					htmltext = "30597-03.htm";
				}
			}
			else if (st.getQuestItemsCount(RingOfTestimony2st) > 0)
			{
				htmltext = "30597-04.htm";
			}
		}
		else if (npcId == Wilford)
		{
			if (cond == 1)
			{
				if ((st.getQuestItemsCount(LilithsElvenWafer) == 0) && (st.getQuestItemsCount(CrystalBrooch) == 0))
				{
					htmltext = "30005-01.htm";
				}
				else if ((st.getQuestItemsCount(LilithsElvenWafer) == 0) && (st.getQuestItemsCount(CrystalBrooch) > 0))
				{
					htmltext = "30005-05.htm";
				}
				else if (st.getQuestItemsCount(LilithsElvenWafer) > 0)
				{
					htmltext = "30005-06.htm";
				}
			}
			else if (st.getQuestItemsCount(RingOfTestimony2st) > 0)
			{
				htmltext = "30005-07.htm";
			}
		}
		else if (npcId == Lilith)
		{
			if (cond == 1)
			{
				if ((st.getQuestItemsCount(CrystalBrooch) > 0) && (st.getQuestItemsCount(LilithsElvenWafer) == 0))
				{
					htmltext = "30368-01.htm";
				}
				else if ((st.getQuestItemsCount(LilithsElvenWafer) > 0) && (st.getQuestItemsCount(CrystalBrooch) == 0))
				{
					htmltext = "30368-04.htm";
				}
			}
			else if (st.getQuestItemsCount(RingOfTestimony2st) > 0)
			{
				htmltext = "30368-05.htm";
			}
		}
		else if (npcId == Bright)
		{
			if (cond == 1)
			{
				if ((st.getQuestItemsCount(BrightsList) == 0) && (st.getQuestItemsCount(EmilysRecipe) == 0) && (st.getQuestItemsCount(MandragoraBouquet) == 0))
				{
					htmltext = "30466-01.htm";
				}
				else if ((st.getQuestItemsCount(MandragoraPetal) < 20) || (st.getQuestItemsCount(CrimsonMoss) < 10))
				{
					htmltext = "30466-04.htm";
				}
				else if ((st.getQuestItemsCount(MandragoraPetal) >= 20) || (st.getQuestItemsCount(CrimsonMoss) >= 10))
				{
					st.takeItems(BrightsList, -1);
					st.takeItems(MandragoraPetal, -1);
					st.takeItems(CrimsonMoss, -1);
					st.giveItems(MandragoraBouquet, 1);
					htmltext = "30466-05.htm";
				}
				else if ((st.getQuestItemsCount(MandragoraBouquet) > 0) && (st.getQuestItemsCount(EmilysRecipe) == 0))
				{
					htmltext = "30466-06.htm";
				}
				else if (st.getQuestItemsCount(EmilysRecipe) > 0)
				{
					htmltext = "30466-07.htm";
				}
			}
			else if (st.getQuestItemsCount(RingOfTestimony2st) > 0)
			{
				htmltext = "30466-08.htm";
			}
		}
		else if (npcId == Emily)
		{
			if (cond == 1)
			{
				if (st.getQuestItemsCount(MandragoraBouquet) != 0)
				{
					htmltext = "30620-01.htm";
				}
				else
				{
					htmltext = "30620-04.htm";
				}
			}
			else if (st.getQuestItemsCount(RingOfTestimony2st) > 0)
			{
				htmltext = "30620-05.htm";
			}
		}
		else if (npcId == Nikola)
		{
			if (cond == 4)
			{
				htmltext = "30621-01.htm";
			}
			else if (cond == 5)
			{
				htmltext = "30621-05.htm";
			}
			else if (cond == 6)
			{
				st.takeItems(PatternOfKeyhole, -1);
				st.giveItems(NikolasList, 1);
				st.giveItems(RecipeTitanKey, 1);
				htmltext = "30621-06.htm";
				st.set("cond", "7");
				st.setState(Quest.STATE_STARTED);
			}
			else if (cond == 7)
			{
				htmltext = "30621-07.htm";
			}
			else if ((cond == 8) && (st.getQuestItemsCount(KeyOfTitan) > 0))
			{
				htmltext = "30621-08.htm";
			}
			else if (cond == 9)
			{
				htmltext = "30621-09.htm";
			}
		}
		else if (npcId == BoxOfTitan)
		{
			if (cond == 5)
			{
				htmltext = "30622-01.htm";
			}
			else if ((cond == 8) && (st.getQuestItemsCount(KeyOfTitan) > 0))
			{
				htmltext = "30622-03.htm";
			}
		}
		return htmltext;
	}
	
	@Override
	public String onKill(L2Npc npc, L2PcInstance player, boolean isPet)
	{
		int npcId = npc.getNpcId();
		QuestState st = checkPlayerState(player, npc, STATE_STARTED);
		int cond = st.getInt("cond");
		for (int[] element : DROPLIST_COND)
		{
			if ((cond == element[0]) && (npcId == element[2]))
			{
				if ((element[3] == 0) || (st.getQuestItemsCount(element[3]) > 0))
				{
					if (element[5] == 0)
					{
						st.rollAndGive(element[4], element[7], element[6], QuestProf);
					}
					else if (st.rollAndGive(element[4], element[7], element[7], element[5], element[6], QuestProf))
					{
						if ((element[1] != cond) && (element[1] != 0))
						{
							st.set("cond", String.valueOf(element[1]));
							st.setState(Quest.STATE_STARTED);
						}
					}
				}
			}
		}
		if ((cond == 7) && (st.getQuestItemsCount(StakatoShell) >= 20) && (st.getQuestItemsCount(ToadLordSac) >= 10) && (st.getQuestItemsCount(SpiderThorn) >= 10))
		{
			st.set("cond", "8");
			st.setState(Quest.STATE_STARTED);
		}
		return null;
	}
	
	public static void onLoad()
	{
		new Q221_TestimonyOfProsperity(221, qn, "Testimony Of Prosperity");
	}
}
